/**
* @file Result.c
*  
* @author W. P. Yao, ywp@pku.edu.cn
* 
* @date 2015-12-11
*/

#include "Result.h"
#include "Basic_Opera.h"


/**
* @Name: Result 
*
* @Param: Step
*/
void Result(int Step)
{
	double *gather_rho, *rho;
	rho = (double *)malloc(sizeof(double)*(M*NUM));
	gather_rho = (double *)malloc(sizeof(double)*(NUM*NUM));
	
	FFT_C2R_For_Output(C_rho_o, R_rho);

	for(j = 0; j < M; j++){
		for(i = 0; i < NUM; i++){
			rho[index] = R_rho[index][0];
		}
	}

	MPI_Barrier(MPI_COMM_WORLD);
	MPI_Gather(rho, M*NUM, MPI_DOUBLE, 
		gather_rho, M*NUM, MPI_DOUBLE, 
		0, MPI_COMM_WORLD);
	MPI_Barrier(MPI_COMM_WORLD);

	if(myrank == 0){
		sprintf(File_Name, "./result/rho_%d.dat", Step);
		Plot_File = fopen(File_Name, "w");
		for(j = 0; j < NUM; j++){
			for(i = 0; i < NUM; i++){
				fprintf(Plot_File,"\t%f\n", gather_rho[index]);
			}
		}
		fclose(Plot_File);
	}
	free(gather_rho);
	free(rho);
}




